<template>
  <!-- 新增标签弹窗 -->
  <el-dialog title="编辑标签" :visible.sync="dialogVisible" width="30%"
             :before-close="close">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-form-item label="标签名" prop="tagName">
        <el-input v-model="form.tagName"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
            <el-button @click="() => close()">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </span>
  </el-dialog>
</template>

<script lang="ts">

import {Component, Prop, Vue} from "vue-property-decorator";
import { EditTag } from "../../apis/apis";
@Component({
  name: "AddTagDialog",
})
export default class EditTagDialog extends Vue {
  @Prop({default:false})dialogVisible!: boolean
  @Prop({ type: Number, default: 0 })oldTag!:number
  form= {
    tagName: ''
  }
  rules={
    tagName: [
      { required: true, message: '请输入标签名', trigger: 'blur' }
    ]
  }
  close():void{
    this.dialogVisible = false
    console.log("关闭成功")
  }

  submit():void{
    const newTag = this.form.tagName
    console.log(this.oldTag)
    var a = this.oldTag
   // console.log(newTag)
   //
    EditTag(this.oldTag,newTag).then((res)=>
    {
      console.log(res)
      if(res.data.code === '200')
      {
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.$emit('refresh')
        this.close()
      }
      else
      {
        this.$message({
          message: '修改失败',
          type: 'error'
        });
      }
    }).catch((err) =>{
      console.log(err);
   })

  }

}
</script>


<style scoped>

</style>